package allod.gui


import java.awt.{Graphics, Dimension, Image}
import javax.swing.JPanel
import net.miginfocom.swing.MigLayout


/**
 *
 * @author allod
 */
class ImagePanel(private var img: Image)
        extends JPanel(new MigLayout("insets 0", "[fill,grow]", "[fill,grow]")) {
  def image = img

  def image_=(image: Image) {
    this.img = image
    repaint()
  }

  override def preferredSize: Dimension = {
    new Dimension(img.getWidth(null), img.getHeight(null))
  }

  override def paint(g: Graphics): Unit = {
    super.paint(g)
    if (img != null) {
      g.drawImage(img, 0, 0, this.size.width, this.size.height, null)
    }
  }
}